class CreateFriends < ActiveRecord::Migration
  def self.up
    create_table "friends", :force => true do |t|
      t.string   :login,                     :limit => 19
      t.string   :email,                     :limit => 100
      t.string   :website,                   :limit => 200
      t.string   :salt,                      :limit => 40
      t.string   :crypted_password,          :limit => 40
      t.string   :password_reset_code,       :limit => 40
      t.string   :activation_code,           :limit => 40
      t.datetime :activated_at
      t.string   :remember_token
      t.datetime :remember_token_expires_at
      t.datetime :created_at
      t.datetime :updated_at
      t.datetime :last_login
      t.string   :selfdesc
      t.text     :domains
      t.text     :info
    end

    create_table :friendships, :force => true do |t|
     t.string   :name,      :limit => 255,     :default => "", :null => false
     t.text     :hint,      :default => ""
     t.boolean  :public,    :default => false, :null => false
     t.integer  :friend_id, :default => 0,     :null => false
     t.integer  :dneirf_id, :default => 0,     :null => false
     t.datetime :created_at
    end    

    add_index :friendships, ["friend_id"], :name => "fk_ships_friend"

    Friend.create!( :login=>"mihael",
                    :password => "taam777",
                    :password_confirmation => "taam777",
                    :email => "miha.ploha@gmail.com",
                    :domains => {:friend => 1, :admin => 1},
                    :activated_at => Time.now.utc,
                    :activation_code => nil)

    %w(taam bit nasi boris marica zvonko vasja franica matevz rosana vojko janez).each do |f|
      Friend.create!( :login => f, 
                      :password => "#{f}#{f}", 
                      :confirm_password => "#{f}#{f}", 
                      :email => "#{f}@eternalfriend.org",
                      :activated_at => Time.now.utc, :activation_code => nil)
    end

  end

  def self.down
    drop_table "friends"
    drop_table "friendships"
  end
end
